<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
    </script>
</head>
<body>
<div class="container">
    <form>
        <div class="form-group">
            <label>电话</label>
            <input type="text" name="phone" class="form-control">
        </div>
        <div class="form-group">
            <label>验证码</label>
            <input type="text" name="code" class="form-control">
            <button type="button" class="getcode">请发送验证码</button>
        </div>
        <div class="form-group">
            <label>邮箱</label>
            <input type="email" name="email" class="form-control">
        </div>
        <div class="form-group">
            <label for="exampleInputPassword1">密码</label>
            <input type="password" name="password" class="form-control" id="exampleInputPassword1">
        </div>
        <div class="form-group">
            <label for="exampleInputPassword2">确认密码</label>
            <input type="password" name="repassword" class="form-control" id="exampleInputPassword2">
        </div>
        <div class="form-group form-check">
            <input type="checkbox" class="form-check-input book" id="exampleCheck1">
            <label class="form-check-label" for="exampleCheck1">是否注册协议</label>
        </div>
        <button type="button" class="btn btn-primary sub">Submit</button>
    </form>
</div>
</body>
</html>
<script>
    $(".getcode").on('click',function () {
        var phone = $("input[name=phone]").val()
        var time = 10;
        var timer = setInterval(function () {
            time--;
            if (time > 0){
                $(".getcode").text(time+"秒后才可发送")
                $(".getcode").prop('disabled','disabled')
            }
            if (time <= 0){
                $(".getcode").text('请发送验证码')
                $(".getcode").prop('disabled',false)
                clearInterval(timer);
            }
        },1000)
        $.ajax({
            url:"{:url('admin/user/send')}",
            type:"post",
            data:{phone:phone},
            success(res){
                alert(res.msg);
            }
        })
    })

    $(".sub").on('click',function () {
        var phone = $("input[name=phone]").val()
        var email = $("input[name=email]").val()
        var password = $("input[name=password]").val()
        var repassword = $("input[name=repassword]").val()
        var code = $("input[name=code]").val()
        var status = $(".book").prop('checked');
        if (status){
            $.ajax({
                url:"{:url('admin/user/tologin')}",
                data:{phone:phone,email:email,password:password,repassword:repassword,code:code},
                type: "post",
                success(res) {
                    alert(res.msg)
                    if (res.code == 300){
                        window.location.href="{:url('admin/user/login')}"
                    }
                }
            })
        }else {
            alert('请先阅读协议');
        }
    })
</script>